package sasku.client.core;

import org.apache.log4j.BasicConfigurator;
import org.apache.log4j.Logger;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;

import sasku.client.core.connection.ServerConnection;
import sasku.client.core.connection.ServerConnectionImpl;
import sasku.client.core.message.listener.AccountMessageListener;
import sasku.client.core.message.listener.PingMessageListener;

public class Main {

	private static Logger log = Logger.getLogger(Main.class);

	public static void main(String... args) {
		BasicConfigurator.configure();
		log.debug("Starting client");

		Settings.getInstance().setHosts("localhost");
		Settings.getInstance().setPort(4200);
		Settings.getInstance().setPassword("mypass");

		ServerConnection connection = new ServerConnectionImpl();
		connection.addListener(new PingMessageListener());
		connection.addListener(new AccountMessageListener());
		connection.connect();
		connection.startConversation();

		new Thread(connection, "ServerConnection").start();

		Display display = new Display();
		Shell shell = new Shell(display);
		shell.setLayout(new GridLayout());
		shell.open();
		while (!shell.isDisposed()) {
			if (!display.readAndDispatch())
				display.sleep();
		}
		display.dispose();
	}

}
